package com.ruoyi.project.remake.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.annotation.TableField;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.remake.domain.TCaseMain;
import com.ruoyi.project.remake.domain.vo.CaseMainVo;
import com.ruoyi.project.remake.service.ITCaseMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.remake.mapper.PayMentMapper;
import com.ruoyi.project.remake.domain.PayMent;
import com.ruoyi.project.remake.service.IPayMentService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 收款模块Service业务层处理
 *
 * @author 孙山伟
 * @date 2023-03-28
 */
@Service
public class PayMentServiceImpl implements IPayMentService
{
    @Autowired
    private PayMentMapper payMentMapper;
    @Autowired
    private ITCaseMainService tCaseMainService;


    /**
     * 查询收款模块
     *
     * @param id 收款模块ID
     * @return 收款模块
     */
    @Override
    public PayMent selectPayMentById(Long id)
    {
        return payMentMapper.selectPayMentById(id);
    }

    /**
     * 查询收款模块列表
     *
     * @param payMent 收款模块
     * @return 收款模块
     */
    @Override
    public List<PayMent> selectPayMentList(PayMent payMent)
    {
        return payMentMapper.selectPayMentList(payMent);
    }

    /**
     * 新增收款模块
     *
     * @param payMent 收款模块
     * @return 结果
     */
    @Override
    @Transactional
    public int insertPayMent(PayMent payMent)
    {
        //收款便增加打印的次数
        CaseMainVo caseMain=tCaseMainService.selectTCaseMainById(payMent.getCaseMainId());
        TCaseMain myCase=new TCaseMain();
        myCase.setId(caseMain.getId());
        myCase.setPrintNumber(null==caseMain.getPrintNumber()?1:caseMain.getPrintNumber()+1);
        tCaseMainService.updateTCaseMain(myCase);
        payMent.setCreateTime(DateUtils.getNowDate());
        return payMentMapper.insertPayMent(payMent);
    }

    /**
     * 修改收款模块
     *
     * @param payMent 收款模块
     * @return 结果
     */
    @Override
    public int updatePayMent(PayMent payMent)
    {
        return payMentMapper.updatePayMent(payMent);
    }

    /**
     * 批量删除收款模块
     *
     * @param ids 需要删除的收款模块ID
     * @return 结果
     */
    @Override
    public int deletePayMentByIds(Long[] ids)
    {
        return payMentMapper.deletePayMentByIds(ids);
    }

    /**
     * 删除收款模块信息
     *
     * @param id 收款模块ID
     * @return 结果
     */
    @Override
    public int deletePayMentById(Long id)
    {
        return payMentMapper.deletePayMentById(id);
    }
}
